<?php
/**
 * Raty
 */
$core->tpl->assign('siteTitle', 'Raty');

if(isset($_GET['task']))
{
	switch ($_GET['task']) {
		case 'new':
			$core->installmentNew();
			break;
		case 'edit':
			$core->installmentEdit();
			break;
		case 'delete':
			$core->installmentList();
			break;
		case 'info':
			$core->installmentInfo();
			break;
		default:
			$core->installmentList();
			break;
	}
}
else
{
	if(isset($_POST['new']) OR isset($_POST['edit']))
	{
	    $val = array();
		
	    $val['name'] = $_POST['name'];
	    $val['description'] = $_POST['description'];
	    $val['bank'] = $_POST['bank'];
		$val['months'] = $_POST['months'];
		$val['term'] = $_POST['term'];
		$val['cost'] = $_POST['cost'];
		$val['email'] = $_POST['email'];
		$val['sms'] = $_POST['sms'];	
		
		$payment = array();
		
		for($i=1;$i<=$_POST['months'];$i++)
		{
			$payment[$i] = 0;
		}
		
		$val['payment'] = implode('|', $payment);
		
        if(isset($_POST['new']))
		{
	        $core->db->insert('installment', $val);
		}
			
		if(isset($_POST['edit']))
		{
			$id = (int)$_POST['edit'];	
			$core->db->update('installment', $val, "id=$id");
		}
	}
	
    $core->installmentList();
}
?>